package com.qianxun.module.datasource1.develop.rest;


import com.qianxun.module.datasource1.develop.service.SysFunctionService;
import com.qianxun.framework.common.util.ObjectUtil;
import com.qianxun.module.datasource1.develop.entity.SysFunction;
import com.qianxun.module.datasource1.develop.dto.SysFunctionDTO;
import com.qianxun.module.datasource1.develop.vo.SysFunctionTreeTableVo;
import com.qianxun.module.base.constant.Result;
import com.qianxun.module.base.bo.ZTreeNode;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
* com.zch.admin.base.entity.SysFunction模型http接口处理
*
* @author: admin
* @date: 2019-11-13
* @version: 1.0.0
*/
@RestController
@RequestMapping("/develop/function")
public class SysFunctionRestController {

    @Resource
    private SysFunctionService baseService;

    @PostMapping(value = {"/update/id/{id}"}, produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
    public Result updateById(@PathVariable(value = "id") Long id, SysFunctionDTO query) {
        SysFunction SysFunction = new SysFunction();
        ObjectUtil.switchAllFieldValue(SysFunction, query);
        baseService.updateById(SysFunction);
        return Result.success();
    }

    @PostMapping(value = {"/update/batch/ids"} ,produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
    public Result updateBatchById(@RequestParam(value = "ids") Long[] ids ,SysFunctionDTO query){
        baseService.updateBatchById(ids ,query);
        return Result.success();
    }

    @PostMapping(value = {"/search/tree"} ,produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
    public String searchTreeList(){
        List<ZTreeNode> list = baseService.searchTreeList();
        return ObjectUtil.toJson(list);
    }

    @RequestMapping(value = {"/search/tree/table"} ,produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
    public Result searchTreeTableList(){
        List<SysFunctionTreeTableVo> list = baseService.searchTreeTableList();
        return Result.success(list);
    }

    /**
     * 查询功能角色对应的功能树
     * @param functionRoleId 功能角色
     * @return
     */
    @PostMapping(value = {"/search/tree/{functionRoleId}"} ,produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
    public String searchFunctionRoleTreeList(@PathVariable(value = "functionRoleId") Integer functionRoleId){
        List<ZTreeNode> list = baseService.searchFunctionRoleTreeList(functionRoleId);
        return ObjectUtil.toJson(list);
    }
}
